package com.qiantu.phone.ui.activity;

import static com.qiantu.phone.BuildConfig.OBS_BASE;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.bumptech.glide.request.RequestOptions;
import com.hjq.base.FragmentPagerAdapter;
import com.hjq.http.listener.HttpCallback;
import com.hjq.toast.ToastUtils;
import com.qiantu.api.db.HandleListener;
import com.qiantu.api.db.LLDeviceDBManager;
import com.qiantu.api.db.LLFloorDBManager;
import com.qiantu.api.db.LLRoomDBManager;
import com.qiantu.api.db.LLSceneDBManager;
import com.qiantu.api.entity.CreateSceneResult;
import com.qiantu.api.entity.DeviceBean;
import com.qiantu.api.entity.FloorBean;
import com.qiantu.api.entity.RoomBean;
import com.qiantu.api.entity.SceneBean;
import com.qiantu.api.http.LLHttpManager;
import com.qiantu.api.http.model.HttpData;
import com.qiantu.phone.R;
import com.qiantu.phone.aop.Log;
import com.qiantu.phone.app.AppActivity;
import com.qiantu.phone.app.AppApplication;
import com.qiantu.phone.event.RefreshDeviceListEvent;
import com.qiantu.phone.event.RefreshSceneEvent;
import com.qiantu.phone.glide.GlideApp;
import com.qiantu.phone.ui.fragment.RoomDeviceFragment;
import com.qiantu.phone.ui.fragment.RoomSceneFragment;
import com.qiantu.phone.utils.SPUtils;
import com.qiantu.phone.widget.ViewPagerIndicator;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import okhttp3.Call;

public class RoomDeviceActivity  extends AppActivity {
    int type;//0:房间；1：楼层；2：全屋
    private ImageView backImageView;
    private String[] tabs;
    private ViewPagerIndicator tabBar;
    private ViewPager viewPager;
    private ViewGroup deviceItemLongClickContainer;
    private View deviceViewContainer;
    private View btn_roomLinkage;
    private TranslateAnimation mShowTranslateAnimation;
    private TranslateAnimation mHideTranslateAnimation;
    @Log
    public static void start(Context context, int type, String roomSerialNo) {
        Intent intent = new Intent(context, RoomDeviceActivity.class);
        intent.putExtra("type",type);
        intent.putExtra("roomSerialNo", roomSerialNo);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_room_device;
    }

    @Override
    protected void initView() {
        String title = getString("title");
        type = getInt("type");
        if(title != null){
            getTitleBar().setTitle(title);
        }
        if(AppApplication.getInstance().getCurHouseInfo().getRoleType() == 2) {
            getTitleBar().getRightView().setVisibility(View.GONE);
        }
//        EventBus.getDefault().register(this);
        backImageView = findViewById(R.id.room_backImage);
        tabBar = findViewById(R.id.tab_bar);
        viewPager = findViewById(R.id.view_pager);
        deviceViewContainer = findViewById(R.id.device_view_container);
        btn_roomLinkage  = findViewById(R.id.btn_roomLinkage);
        deviceItemLongClickContainer = findViewById(R.id.device_item_long_click_container);
        setOnClickListener(deviceItemLongClickContainer,btn_roomLinkage);
        initViewPager();
    }


    RoomSceneFragment sceneFragment;
    RoomDeviceFragment roomDeviceFragment;
    private void initViewPager() {
        FragmentPagerAdapter<Fragment> mPagerAdapter = new FragmentPagerAdapter<>(this);
//        switchSceneRecommend = SPUtils.getInstance().getBoolean("switchSceneRecommend", true);
//        if(switchSceneRecommend){
//            tabs = new String[]{getString(R.string.recommend), getString(R.string.scene), getString(R.string.linkage), getString(R.string.time)};
//            mPagerAdapter.addFragment(new RecommendSceneFragment());
//        }else{
        sceneFragment = RoomSceneFragment.newInstance(type,getString("roomSerialNo"));
        roomDeviceFragment = RoomDeviceFragment.newInstance(type,getString("roomSerialNo"));
        String firstShow =  SPUtils.getInstance().getString ("firstShow");
        Map<String,String> firstShowMap;
        if(firstShow.equals("")){
            firstShowMap = new HashMap<>();
        }else{
            firstShowMap = JSON.parseObject(firstShow,new TypeReference<HashMap<String, String>>() {});
        }
        if(firstShowMap.containsKey(AppApplication.getInstance().getCurrentHouseSerialNo()) && firstShowMap.get(AppApplication.getInstance().getCurrentHouseSerialNo()).equals("0")){
            tabs = new String[]{getString(R.string.scene), getString(R.string.device)};
            mPagerAdapter.addFragment(sceneFragment);
            mPagerAdapter.addFragment(roomDeviceFragment);
        }else{
            tabs = new String[]{getString(R.string.device),getString(R.string.scene)};
            mPagerAdapter.addFragment(roomDeviceFragment);
            mPagerAdapter.addFragment(sceneFragment);
        }

//        }
        viewPager.setAdapter(mPagerAdapter);
        tabBar.setupViewpager(viewPager);
        tabBar.setTitles(tabs);
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                ((RoomDeviceActivity) getActivity()).hideLongClickFloatView();
            }

            @Override
            public void onPageSelected(int position) {
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
    @Override
    protected void initData() {
        String roomSerialNo = getString("roomSerialNo");
        if(type == 0){
            RoomBean roomBean = LLRoomDBManager.getInstance(getContext()).getRoomByRoomSerialNo(roomSerialNo);
            if(roomBean == null){
                finish();
                return;
            }
            String url = OBS_BASE.substring(0,OBS_BASE.length()-1) + roomBean.getPicUrl();
            GlideApp.with(backImageView)
                    .load(url)
                    .into(backImageView);
        }else{
            FloorBean floorBean = LLFloorDBManager.getInstance(getContext()).getFloorByFloorSerialNo(roomSerialNo);
            if(floorBean == null){
                finish();
                return;
            }
            String url = OBS_BASE.substring(0,OBS_BASE.length()-1) + floorBean.getPicUrl();
            GlideApp.with(backImageView)
                    .load(url)
                    .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(50,0, RoundedCornersTransformation.CornerType.TOP)))
                    .into(backImageView);
        }
    }

    public void hideLongClickFloatView() {
        if (deviceItemLongClickContainer.getVisibility() == View.GONE) {
            return;
        }
        deviceItemLongClickContainer.removeAllViews();
        deviceItemLongClickContainer.setVisibility(View.GONE);
    }

    public void longClickDeviceItem(int left, int top, int width, int height, DeviceBean device, boolean isFavourite) {
        if(AppApplication.getInstance().getCurHouseInfo().getRoleType() == 2){
            return;
        }
        deviceItemLongClickContainer.setVisibility(View.VISIBLE);
        deviceItemLongClickContainer.removeAllViews();
        int shadowSize = getResources().getDimensionPixelSize(R.dimen.dp_4);
        FrameLayout.LayoutParams fl = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        fl.leftMargin = left + shadowSize;
        fl.topMargin = top + shadowSize;
        fl.width = width - shadowSize * 2;
        fl.height = height - shadowSize * 2;
        View view;
//        //设备展开并且不是开关类型
//        if (device.isSwitch() && !SWITCH.stringType.equals(device.getDeviceType())) {
        if (device.getIsSwitch() && device.getHasCard() == 1) {//设备展开并且是可展开类型
            view = LayoutInflater.from(getContext()).inflate(R.layout.home_big_device_long_click_item, null, false);
        } else {
            view = LayoutInflater.from(getContext()).inflate(R.layout.home_device_long_click_item, null, false);
        }
        DeviceItemOnClickListener deviceItemOnClickListener = new DeviceItemOnClickListener(device, isFavourite);
        View btnSwitch = view.findViewById(R.id.btn_switch);
//        if (SWITCH.stringType.equals(device.getDeviceType())) {
        if (device.getHasCard() == 0) {//不可展开类型
            btnSwitch.setVisibility(View.GONE);
        } else {
            btnSwitch.setVisibility(View.VISIBLE);
            btnSwitch.setOnClickListener(deviceItemOnClickListener);
        }
        view.findViewById(R.id.btn_topping).setOnClickListener(deviceItemOnClickListener);
        view.findViewById(R.id.btn_setting).setOnClickListener(deviceItemOnClickListener);
        deviceItemLongClickContainer.addView(view, fl);
    }

    public void longClickSceneItem(int left, int top, int width, int height, SceneBean scene, List<SceneBean> sceneList, boolean isFavourite) {
        if(AppApplication.getInstance().getCurHouseInfo().getRoleType() == 2){
            return;
        }
        deviceItemLongClickContainer.setVisibility(View.VISIBLE);
        deviceItemLongClickContainer.removeAllViews();
        int shadowSize = getResources().getDimensionPixelSize(R.dimen.dp_4);
        FrameLayout.LayoutParams fl = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        fl.leftMargin = left + shadowSize;
        fl.topMargin = top + shadowSize;
        fl.width = width - shadowSize * 2;
        fl.height = height - shadowSize * 2;
        View view = LayoutInflater.from(getContext()).inflate(R.layout.home_scene_long_click_item, null, false);

        SceneItemOnClickListener sceneItemOnClickListener = new SceneItemOnClickListener(scene,sceneList);

        view.findViewById(R.id.btn_topping).setOnClickListener(sceneItemOnClickListener);
        view.findViewById(R.id.btn_copy).setOnClickListener(sceneItemOnClickListener);
        deviceItemLongClickContainer.addView(view, fl);
    }
    private class DeviceItemOnClickListener implements View.OnClickListener {

        private DeviceBean mDevice;

        private boolean isFavourite;

        public DeviceItemOnClickListener(DeviceBean device, boolean isFavourite) {
            mDevice = device;
            this.isFavourite = isFavourite;
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_topping:
                    if(type == 2){
                        LLHttpManager.topHouseDevice(RoomDeviceActivity.this, AppApplication.getInstance().getCurrentHouseSerialNo(), 0,mDevice.getDeviceGroup() == 0 ? 0 : 1, mDevice.getDeviceSerialNo(), new HttpCallback<HttpData<Void>>(null) {
                            @Override
                            public void onStart(Call call) {
                                showDialog(getString(R.string.setting));
                            }

                            @Override
                            public void onSucceed(HttpData<Void> result) {
                                LLDeviceDBManager.getInstance(getContext()).updateDeviceTop(-1, mDevice.getDeviceSerialNo(), "");
                                EventBus.getDefault().post(new RefreshDeviceListEvent(getString("roomSerialNo"), mDevice.getIsFavourite()));
                            }

                            @Override
                            public void onFail(Exception e) {
                                toast(R.string.set_failed);
                            }

                            @Override
                            public void onEnd(Call call) {
                                hideDialog();
                            }
                        });
                    }else{
                        HttpCallback<HttpData<Void>> callback = new HttpCallback<HttpData<Void>>(null) {
                            @Override
                            public void onStart(Call call) {
                                showDialog(getString(R.string.setting));
                            }

                            @Override
                            public void onSucceed(HttpData<Void> result) {
                                LLDeviceDBManager.getInstance(getContext()).updateDeviceTop(type == 0 ? 1 : 3, mDevice.getDeviceSerialNo(), type == 0 ? mDevice.getRoomSerialNo() : mDevice.getFloorSerialNo());
                                EventBus.getDefault().post(new RefreshDeviceListEvent(getString("roomSerialNo"), mDevice.getIsFavourite()));
                            }

                            @Override
                            public void onFail(Exception e) {
                                toast(R.string.set_failed);
                            }

                            @Override
                            public void onEnd(Call call) {
                                hideDialog();
                            }
                        };
                        if(mDevice.getDeviceGroup() == 0){
                            LLHttpManager.topDevice(RoomDeviceActivity.this, mDevice.getDeviceSerialNo(), true, type == 0 ? 1 : 3,callback);
                        }else{
                            LLHttpManager.topGroupDevice(RoomDeviceActivity.this, mDevice.getDeviceSerialNo(), true, type == 0 ? 1 : 3, type == 0 ? mDevice.getRoomSerialNo() : mDevice.getFloorSerialNo(),callback);
                        }
                    }
                    break;
                case R.id.btn_switch:
                    HttpCallback<HttpData<Void>> callback = new HttpCallback<HttpData<Void>>(null) {
                        @Override
                        public void onStart(Call call) {
                            showDialog(getString(R.string.setting));
                        }

                        @Override
                        public void onSucceed(HttpData<Void> result) {
                            LLDeviceDBManager.getInstance(getContext()).updateExpand(mDevice.getDeviceSerialNo(), !mDevice.getIsSwitch());
                            EventBus.getDefault().post(new RefreshDeviceListEvent(getString("roomSerialNo"), mDevice.getIsFavourite()));
                        }

                        @Override
                        public void onFail(Exception e) {
                            toast(R.string.set_failed);
                        }

                        @Override
                        public void onEnd(Call call) {
                            hideDialog();
                        }
                    };
                    if(mDevice.getDeviceGroup() == 0){
                        LLHttpManager.deviceIsSwitch(RoomDeviceActivity.this, mDevice.getDeviceSerialNo(), !mDevice.getIsSwitch(), callback);
                    }else{
                        LLHttpManager.groupDeviceIsSwitch(RoomDeviceActivity.this, mDevice.getDeviceSerialNo(), !mDevice.getIsSwitch(), callback);
                    }

                    break;
                case R.id.btn_setting:
                    DeviceSettingActivity.start(getContext(), mDevice.getDeviceSerialNo(), true);
                    break;
            }
            hideLongClickFloatView();
        }
    }

    private class SceneItemOnClickListener implements View.OnClickListener {

        private SceneBean mScene;
        private List<SceneBean> mSceneList;

        public SceneItemOnClickListener(SceneBean scene, List<SceneBean> sceneList) {
            mScene = scene;
            sceneList.remove(sceneList.size() - 1);
            mSceneList = sceneList;
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_topping:
                    if(type == 2){
                        LLHttpManager.topHouseDevice(RoomDeviceActivity.this, AppApplication.getInstance().getCurrentHouseSerialNo(), 0,2, mScene.getSceneSerialNo(), new HttpCallback<HttpData<Void>>(null) {
                            @Override
                            public void onStart(Call call) {
                                showDialog(getString(R.string.setting));
                            }

                            @Override
                            public void onSucceed(HttpData<Void> result) {
                                mSceneList.remove(mScene);
                                mSceneList.add(0,mScene);
                                for(int i = 0;i < mSceneList.size();i++){
                                    mSceneList.get(i).setFloorGlobalSort(i);
                                }
                                LLSceneDBManager.getInstance(getActivity()).putInTx(mSceneList, new HandleListener() {
                                    @Override
                                    public void onCompleted() {
                                        EventBus.getDefault().post(new RefreshSceneEvent());
                                    }
                                });
                            }

                            @Override
                            public void onFail(Exception e) {
                                toast(R.string.set_failed);
                            }

                            @Override
                            public void onEnd(Call call) {
                                hideDialog();
                            }
                        });
                    }else if(type == 1){
                        mSceneList.remove(mScene);
                        mSceneList.add(0,mScene);
                        LLHttpManager.floorSceneSort(RoomDeviceActivity.this, mSceneList, new HttpCallback<HttpData<Void>>(null) {
                            @Override
                            public void onStart(Call call) {
                                showDialog(getString(R.string.setting));
                            }

                            @Override
                            public void onSucceed(HttpData<Void> result) {
                                LLSceneDBManager.getInstance(getActivity()).putInTx(mSceneList, new HandleListener() {
                                    @Override
                                    public void onCompleted() {
                                        EventBus.getDefault().post(new RefreshSceneEvent());
                                    }
                                });
                            }

                            @Override
                            public void onFail(Exception e) {
                                toast(R.string.set_failed);
                            }

                            @Override
                            public void onEnd(Call call) {
                                hideDialog();
                            }
                        });
                    }else{
                        mSceneList.remove(mScene);
                        mSceneList.add(0,mScene);
                        LLHttpManager.roomSceneSort(RoomDeviceActivity.this, mSceneList, new HttpCallback<HttpData<Void>>(null) {
                            @Override
                            public void onStart(Call call) {
                                showDialog(getString(R.string.setting));
                            }

                            @Override
                            public void onSucceed(HttpData<Void> result) {
                                LLSceneDBManager.getInstance(getActivity()).putInTx(mSceneList, new HandleListener() {
                                    @Override
                                    public void onCompleted() {
                                        EventBus.getDefault().post(new RefreshSceneEvent());
                                    }
                                });
                            }

                            @Override
                            public void onFail(Exception e) {
                                toast(R.string.set_failed);
                            }

                            @Override
                            public void onEnd(Call call) {
                                hideDialog();
                            }
                        });
                    }
                    break;
                case R.id.btn_copy:
                    LLHttpManager.copyScene(RoomDeviceActivity.this, mScene.getSceneSerialNo(), new HttpCallback<HttpData<CreateSceneResult>>(null) {
                        @Override
                        public void onStart(Call call) {
                            showDialog(getString(R.string.setting));
                        }

                        @Override
                        public void onSucceed(HttpData<CreateSceneResult> result) {
                            LLSceneDBManager.getInstance(getContext()).put(result.getData().getCreateSceneDto());
                            EventBus.getDefault().post(new RefreshSceneEvent());
                        }

                        @Override
                        public void onFail(Exception e) {
                            toast(R.string.set_failed);
                        }

                        @Override
                        public void onEnd(Call call) {
                            hideDialog();
                        }
                    });
                    break;
            }
            hideLongClickFloatView();
        }
    }

    private Fragment deviceFragment;

    private FragmentManager mFragmentManager;
    public void showDeviceView(View clickView, Fragment fragment) {
        if (mFragmentManager == null) {
            mFragmentManager = getSupportFragmentManager();
        }
        FragmentTransaction transaction = mFragmentManager.beginTransaction();
        if (deviceFragment != null && deviceFragment.isAdded()) {
            transaction.remove(deviceFragment);
        }
        deviceFragment = mFragmentManager.findFragmentByTag("device_view");
        if (deviceFragment != null && deviceFragment.isAdded()) {
            transaction.remove(deviceFragment);
        }
        deviceFragment = fragment;
        transaction.add(R.id.device_view_container, fragment, "device_view");
        // 事务提交
        transaction.commitNowAllowingStateLoss();
        deviceViewContainer.setVisibility(View.VISIBLE);
        ViewGroup contentView = deviceViewContainer.findViewById(R.id.content_view);
        if (contentView.getChildCount() > 0) {
            View deviceView = contentView.getChildAt(0);
            showTopBottomAnimation(deviceView);
//            showScaleAnimation(clickView, deviceView);
        }
    }

    public boolean hideDeviceView() {
        if (mFragmentManager == null) {
            mFragmentManager = getSupportFragmentManager();
        }
        deviceFragment = mFragmentManager.findFragmentByTag("device_view");
        if (deviceFragment != null) {
            ViewGroup contentView = deviceViewContainer.findViewById(R.id.content_view);
            if (contentView.getChildCount() > 0) {
                View deviceView = contentView.getChildAt(0);
                hideTopBottomAnimation(deviceView);
                return true;
            }
        }
        return false;
    }

    public void showDeviceAddView(String roomSerialNo) {
        Intent intent = new Intent(getContext(), RoomDeviceAddActivity.class);
        intent.putExtra("roomSerialNo",roomSerialNo);
        intent.putExtra("type",2);
        getContext().startActivity(intent);
    }

    public void showSettingView(DeviceBean deviceBean) {
        DeviceSettingActivity.start(getContext(), deviceBean.getDeviceSerialNo(), false);
    }

    private void showTopBottomAnimation(View deviceView) {
        if (mShowTranslateAnimation == null) {
            mShowTranslateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0);
            mShowTranslateAnimation.setDuration(300);//跑一个周期所用时长
            mShowTranslateAnimation.setInterpolator(new FastOutSlowInInterpolator());
        }
        deviceView.setVisibility(View.VISIBLE);
        deviceView.startAnimation(mShowTranslateAnimation);
    }

    private void hideTopBottomAnimation(View deviceView) {
        if (mHideTranslateAnimation == null) {
            mHideTranslateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1);
            mHideTranslateAnimation.setDuration(300);//跑一个周期所用时长
            mHideTranslateAnimation.setInterpolator(new FastOutSlowInInterpolator());
            mHideTranslateAnimation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    FragmentTransaction transaction = mFragmentManager.beginTransaction();
                    if (deviceFragment != null && deviceFragment.isAdded()) {
                        transaction.remove(deviceFragment);
                    }
                    // 事务提交
                    transaction.commitNowAllowingStateLoss();
                    deviceViewContainer.setVisibility(View.GONE);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
        }
        deviceView.startAnimation(mHideTranslateAnimation);
    }

    @Override
    public void onRightClick(View view) {
        String roomSerialNo = getString("roomSerialNo");
        if(type == 0){
            RoomBean roomBean = LLRoomDBManager.getInstance(getContext()).getRoomByRoomSerialNo(roomSerialNo);
            FloorBean floorBean = LLFloorDBManager.getInstance(getContext()).getFloorByFloorSerialNo(roomBean.getFloorSerialNo());
            Intent intent = new Intent(getActivity(), RoomSettingActivity.class);
            intent.putExtra("floorName", floorBean.getFloorName());
            intent.putExtra("floorType", floorBean.getType());
            intent.putExtra("roomName", roomBean.getRoomName());
            intent.putExtra("roomSerialNo", roomBean.getRoomSerialNo());
            intent.putExtra("roomSerialNo", roomBean.getRoomSerialNo());
            intent.putExtra("floorSerialNo", roomBean.getFloorSerialNo());
            intent.putExtra("roomType",roomBean.getRoomTypeId());
            intent.putExtra("shareCount",roomBean.getShareCount());
            startActivity(intent);
        }else{
            FloorBean floorBean = LLFloorDBManager.getInstance(getContext()).getFloorByFloorSerialNo(roomSerialNo);
            Intent intent = new Intent(getActivity(), FloorSettingActivity.class);
            intent.putExtra("floorSerialNo", roomSerialNo);
            intent.putExtra("type",type);
            startActivity(intent);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.device_item_long_click_container:
                hideLongClickFloatView();
                break;
            case R.id.btn_roomLinkage:
                //0:房间；1：楼层；2：全屋
                if (type == 2) {
                    RoomLinkageActivity.start(getContext(),"",0);

                } else if (type == 1) {
                    String roomSerialNo = getString("roomSerialNo");
                    RoomLinkageActivity.start(getContext(),roomSerialNo,1);
                } else if (type == 0) {
                    String roomSerialNo = getString("roomSerialNo");
                    RoomLinkageActivity.start(getContext(),roomSerialNo,2);
                }

                break;
        }
    }

    @Override
    public void onBackPressed() {
        if (deviceItemLongClickContainer.getVisibility() == View.VISIBLE) {
            hideLongClickFloatView();
            return;
        }
        if (hideDeviceView()) {
            return;
        }

        super.onBackPressed();
    }

    @Override
    protected void onDestroy() {
//        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }

    @Override
    public void onResume() {
        initData();
        super.onResume();
    }


}
